
<template>
    <div>
      <el-card style="width: 50%;margin: 20px auto;">
        <el-form :model="user" label-width="100px" style="padding-right: 50px">
          <div style="margin: 15px; text-align: center">
          
            <el-upload action="/oss"  :headers="{ Authorization:'Bearer ' + token }" 
                     :on-success="handleAvatarSuccess">

                        <img v-if="user.icon" :src="this.user.icon" class="avatar">
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
               
          </div>
          <el-form-item label="账号" prop="username">
            <el-input v-model="user.username" disabled placeholder="账号"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="user.password" type="password"  placeholder="密码"></el-input>
          </el-form-item>
         
          <div style="text-align: center; margin-bottom: 20px">
            <el-button type="primary" @click="update">保 存</el-button>
          </div>
        </el-form>
      </el-card>
    </div>
  </template>
  
  <script>
  import service from '@/request';
  export default {
    name: "AdminPerson",
    data() {
      return {
        user:{},
        form:{}
      }
    },
    created() {
  
    },
    mounted(){
        this.token = window.localStorage.getItem("token")
        this.user=JSON.parse(window.localStorage.getItem("userinfo"))
    },
    methods: {
        handleAvatarSuccess(response, file, fileList) {
 this.user.icon=response.data
      },
     async update() {
      this.user.roleIds=[1]
       const res=await service.put("/sys/user",this.user);
       console.log(res);
       if(res.code == 200){
        this.$message.success(res.data)
        window.localStorage.setItem("userinfo",JSON.stringify(this.user))
       }
      },
      handleAvatarSuccess1(response, file, fileList) {
        // 把user的头像属性换成上传的图片的链接
        this.$set(this.user, 'license', response.data)
      },
    }
  }
  </script>
  
  <style scoped>
  /deep/.el-form-item__label {
    font-weight: bold;
  }
  /deep/.el-upload {
    border-radius: 50%;
  }
  /deep/.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border-radius: 50%;
  }
  /deep/.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px !important;
    text-align: center;
    border-radius: 50%;
  }
  .avatar {
    width: 120px;
    height: 120px;
    display: block;
    border-radius: 50%;
  }
  </style>